#!/bin/bash

# Checks out the latest version and repackages it for use.
# Keeps what is needed, but tests etc. go.
# Requires bash, sed, hg etc.

# Jan Varho


# Prepare directories, clone the repo
mkdir -p re2-out
hg clone https://re2.googlecode.com/hg re2-tmp


# Copy files, renaming include paths and .cc->.cpp

cd re2-tmp/re2

for i in `ls *.cc`
do
	cat $i | sed 's/#include "re2\/\(.*\)/#include "\1/' | sed 's/#include "util\/\(.*\)/#include "\1/' > ../../re2-out/${i%cc}cpp
done

for i in `ls *.h`
do
	cat $i | sed 's/#include "re2\/\(.*\)/#include "\1/' | sed 's/#include "util\/\(.*\)/#include "\1/' > ../../re2-out/$i
done

cd ../util

for i in `ls *.cc`
do
	cat $i | sed 's/#include "re2\/\(.*\)/#include "\1/' | sed 's/#include "util\/\(.*\)/#include "\1/' > ../../re2-out/${i%cc}cpp
done
for i in `ls *.h`
do
	cat $i | sed 's/#include "re2\/\(.*\)/#include "\1/' | sed 's/#include "util\/\(.*\)/#include "\1/' > ../../re2-out/$i
done

# Copy licensing info

cd ..

cp AUTHORS ../re2-out
cp CONTRIBUTORS ../re2-out
cp LICENSE ../re2-out
cp README ../re2-out

rm -Rf re2-tmp

